package com.huluobo.a2206douyindemo.videos;

import androidx.lifecycle.MutableLiveData;

import com.google.gson.Gson;
import com.huluobo.base.bean.CommentBeanResult;
import com.huluobo.base.bean.CommonBeanResult;
import com.huluobo.base.bean.VideoBeanResult;
import com.huluobo.base.mvvm.BaseViewModel;
import com.huluobo.base.net.Const;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * Created by LC on 2024/8/16.
 */
public class VideoViewModel extends BaseViewModel<VideoRepo> {
    MutableLiveData<VideoBeanResult> getVideoListSuccess = new MutableLiveData<>();
    MutableLiveData<String> getVideoListFailed = new MutableLiveData<>();

    MutableLiveData<CommonBeanResult> likeVideoSuccess = new MutableLiveData<>();
    MutableLiveData<String> likeVideoFailed = new MutableLiveData<>();

    MutableLiveData<CommonBeanResult> noLikeVideoSuccess = new MutableLiveData<>();
    MutableLiveData<String> noLikeVideoFailed = new MutableLiveData<>();

    MutableLiveData<CommonBeanResult> followAuthSuccess = new MutableLiveData<>();
    MutableLiveData<String> followAuthFailed = new MutableLiveData<>();

    MutableLiveData<CommentBeanResult> getCommentSuccess = new MutableLiveData<>();
    MutableLiveData<String> getCommentFailed = new MutableLiveData<>();

    MutableLiveData<CommentBeanResult> sendCommentSuccess = new MutableLiveData<>();
    MutableLiveData<String> sendCommentFailed = new MutableLiveData<>();

    public void sendComment(int videoId, String msg) {
        Map<String, Object> map = new HashMap<>();
        map.put(Const.PARAM_VIDEO_ID, videoId);
        map.put(Const.PARAM_MSG, msg);

        String json = new Gson().toJson(map);
        RequestBody body = RequestBody.create(MediaType.parse(Const.MEDIA_TYPE), json);
        repo.sendComment(body, sendCommentSuccess, sendCommentFailed);
    }

    public void getComments(int videoId) {
        repo.getComments(videoId, getCommentSuccess, getCommentFailed);
    }

    public void followAuth(String authname) {
        Map<String, String> map = new HashMap<>();
        map.put(Const.PARAM_AUTHNAME, authname);
        String json = new Gson().toJson(map);
        RequestBody body = RequestBody.create(MediaType.parse(Const.MEDIA_TYPE), json);
        repo.followAuth(body, followAuthSuccess, followAuthFailed);
    }

    public void likeVideo(int videoId) {
        repo.likeVideo(videoId, likeVideoSuccess, likeVideoFailed);
    }

    public void noLikeVideo(int videoId) {
        repo.noLikeVideo(videoId, noLikeVideoSuccess, noLikeVideoFailed);
    }

    public void getVideoList(int currentPage, int pageSize) {
        repo.getVideoList(currentPage, pageSize, getVideoListSuccess, getVideoListFailed);
    }

    @Override
    protected VideoRepo createRepo() {
        return new VideoRepo();
    }
}
